using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.PatientDomain;
using ShivamEMR.Model.DataInterfaces.PatientDataInterf;
using ShivamEMR.Model;

namespace ShivamEMR.Web.Areas.Patient.Controllers
{   
    public class PatientAllergyGroupController : Controller
    {
		private readonly IPatientAllergyGroupRepository patientallergygroupRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public PatientAllergyGroupController() //: this(new PatientAllergyGroupRepository())
        {
            patientallergygroupRepository = Registry.RepositoryFactory.GetPatientAllergyGroupRepository();
        }

        public PatientAllergyGroupController(IPatientAllergyGroupRepository patientallergygroupRepository)
        {
			this.patientallergygroupRepository = patientallergygroupRepository;
        }

        //
        // GET: /PatientAllergyGroup/

        public ViewResult Index()
        {
            return View(patientallergygroupRepository.All);//Including(patientallergygroup => patientallergygroup.Parents, patientallergygroup => patientallergygroup.Children, patientallergygroup => patientallergygroup.PatientAllergies));
        }

        //
        // GET: /PatientAllergyGroup/Details/5

        public ViewResult Details(int id)
        {
            return View(patientallergygroupRepository.Find(id));
        }

        //
        // GET: /PatientAllergyGroup/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /PatientAllergyGroup/Create

        [HttpPost]
        public ActionResult Create(PatientAllergyGroup patientallergygroup)
        {
            if (ModelState.IsValid) {
                patientallergygroupRepository.Create(patientallergygroup);
                patientallergygroupRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }
        
        //
        // GET: /PatientAllergyGroup/Edit/5
 
        public ActionResult Edit(int id)
        {
             return View(patientallergygroupRepository.Find(id));
        }

        //
        // POST: /PatientAllergyGroup/Edit/5

        [HttpPost]
        public ActionResult Edit(PatientAllergyGroup patientallergygroup)
        {
            if (ModelState.IsValid) {
                patientallergygroupRepository.Update(patientallergygroup);
                patientallergygroupRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }

        //
        // GET: /PatientAllergyGroup/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View(patientallergygroupRepository.Find(id));
        }

        //
        // POST: /PatientAllergyGroup/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            var pa = patientallergygroupRepository.Find(id);
            patientallergygroupRepository.Delete(pa);
            patientallergygroupRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

